package com.itbz.dao.Impl;

import com.itbz.dao.RoomDao;
import com.itbz.pojo.Room;
import com.itbz.util.JdbcDruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class RoomDaoImpl implements RoomDao {

    /**
     * 查询所有班级
     * @return
     */
    @Override
    public List<Room> selectAll() {
        Connection conn=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        List<Room>list=new ArrayList<>();
        try {
            //连接数据库
            conn=JdbcDruidUtil.getConnection();
            ps=conn.prepareStatement("select * from room");
            //执行sql语句
            rs = ps.executeQuery();
            while (rs.next()){
                Room room=new Room();
                room.setRid(rs.getInt(1));
                room.setRname(rs.getString(2));
                list.add(room);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JdbcDruidUtil.closeResource(rs,ps,conn);
        }
        return list;
    }
}

